package view.systemAdmiView;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import dao.BookDao;
import dao.BookTypeDao;
import dao.UserDao;
import model.Book;
import model.BookType;
import model.User;
import util.DbUtil;
import util.StringUtil;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.ButtonGroup;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;

public class UserImfManageInterFrm extends JInternalFrame {
	private JTable userTable;
	private JTextField s_userNameTxt;
	private JTextField idTxt;
	private JTextField userNameTxt;
	private JTextField passWordTxt;
	private JTextField telTxt;
	private JTextField emailTxt;
	private JLabel s_userType; 
	private JRadioButton manJrb;
	private JRadioButton femaleJrb;
	private JComboBox userTypeJcb ;
	private JComboBox s_userTypeJcb ;
	
	
	private DbUtil dbUtil=new DbUtil();
	private UserDao userDao=new UserDao();
	
	
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JTextField s_telTxt;
	private JTextField s_passWordTxt;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UserImfManageInterFrm frame = new UserImfManageInterFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public UserImfManageInterFrm() {
		getContentPane().setBackground(new Color(230, 230, 250));
		setTitle("用户信息维护界面");
		setIconifiable(true);
		setClosable(true);
		setBounds(100, 100, 1758, 914);
		
		JScrollPane allUserImfScrollPane = new JScrollPane();
		
		
		JPanel userSearchPanel = new JPanel();
		userSearchPanel.setBackground(new Color(255, 218, 185));
		userSearchPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u67E5\u8BE2\u4FE1\u606F", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		
		JPanel userPanel = new JPanel();
		userPanel.setBackground(new Color(255, 218, 185));
		userPanel.setBorder(new TitledBorder(null, "\u4FE1\u606F\u7EF4\u62A4", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JLabel title = new JLabel("用户信息维护");
		title.setIcon(new ImageIcon(UserImfManageInterFrm.class.getResource("/images/systemAdmi/用户信息维护 (2).png")));
		title.setFont(new Font("宋体", Font.BOLD, 40));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(24)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
								.addComponent(userPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(userSearchPanel, GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE))
							.addGap(49)
							.addComponent(allUserImfScrollPane, GroupLayout.DEFAULT_SIZE, 873, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(626)
							.addComponent(title)))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(16)
					.addComponent(title)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(allUserImfScrollPane, GroupLayout.DEFAULT_SIZE, 736, Short.MAX_VALUE)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(userSearchPanel, GroupLayout.PREFERRED_SIZE, 257, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
							.addComponent(userPanel, GroupLayout.PREFERRED_SIZE, 435, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		
		JLabel lblNewLabel_2 = new JLabel("编  号：");
		lblNewLabel_2.setFont(new Font("宋体", Font.BOLD, 25));
		
		idTxt = new JTextField();
		idTxt.setFont(new Font("宋体", Font.BOLD, 25));
		idTxt.setEditable(false);
		idTxt.setColumns(10);
		
		JLabel lblNewLabel_3 = new JLabel("用户名：");
		lblNewLabel_3.setFont(new Font("宋体", Font.BOLD, 25));
		
		userNameTxt = new JTextField();
		userNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		userNameTxt.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("密  码：");
		lblNewLabel_4.setFont(new Font("宋体", Font.BOLD, 25));
		
		passWordTxt = new JTextField();
		passWordTxt.setFont(new Font("宋体", Font.BOLD, 25));
		passWordTxt.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("性 别：");
		lblNewLabel_5.setFont(new Font("宋体", Font.BOLD, 25));
		
		JLabel lblNewLabel_6 = new JLabel("用户类型：");
		lblNewLabel_6.setFont(new Font("宋体", Font.BOLD, 25));
		
		String []types2= {"学生","老师","系统管理员","图书管理员"};
		userTypeJcb = new JComboBox(types2);
		userTypeJcb.setFont(new Font("宋体", Font.BOLD, 25));
		
		JLabel lblNewLabel_7 = new JLabel("手机号码：");
		lblNewLabel_7.setFont(new Font("宋体", Font.BOLD, 25));
		
		telTxt = new JTextField();
		telTxt.setFont(new Font("宋体", Font.BOLD, 25));
		telTxt.setColumns(10);
		
		JLabel lblNewLabel_8 = new JLabel("邮 件：");
		lblNewLabel_8.setFont(new Font("宋体", Font.BOLD, 25));
		
		emailTxt = new JTextField();
		emailTxt.setFont(new Font("宋体", Font.BOLD, 25));
		emailTxt.setColumns(10);
		
		JButton alterButton = new JButton("修改");
		alterButton.setIcon(new ImageIcon(UserImfManageInterFrm.class.getResource("/images/readerAdim/修改.png")));
		alterButton.setFont(new Font("宋体", Font.BOLD, 25));
		alterButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				userUpdateActionPerformed(e);
			}
		});
		
		JButton deleteButton = new JButton("删除");
		deleteButton.setFont(new Font("Dialog", Font.BOLD, 25));
		deleteButton.setIcon(new ImageIcon(UserImfManageInterFrm.class.getResource("/images/bookAdmi/取消.png")));
		deleteButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				userDeleteActionPerformed(e);
				
			}
		});
		
		
		manJrb = new JRadioButton("男");
		manJrb.setBackground(new Color(255, 218, 185));
		manJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup.add(manJrb);
		
		femaleJrb = new JRadioButton("女");
		femaleJrb.setBackground(new Color(255, 218, 185));
		femaleJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup.add(femaleJrb);
		GroupLayout gl_userPanel = new GroupLayout(userPanel);
		gl_userPanel.setHorizontalGroup(
			gl_userPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_userPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_userPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_userPanel.createSequentialGroup()
							.addComponent(lblNewLabel_7)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(telTxt, 216, 216, 216))
						.addGroup(gl_userPanel.createSequentialGroup()
							.addComponent(lblNewLabel_2)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_userPanel.createSequentialGroup()
							.addGroup(gl_userPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel_4)
								.addComponent(lblNewLabel_6))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_userPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(userTypeJcb, 0, 216, Short.MAX_VALUE)
								.addComponent(passWordTxt, 216, 216, 216))))
					.addGap(73)
					.addGroup(gl_userPanel.createParallelGroup(Alignment.LEADING, false)
						.addGroup(gl_userPanel.createSequentialGroup()
							.addComponent(lblNewLabel_3)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(userNameTxt))
						.addGroup(gl_userPanel.createSequentialGroup()
							.addComponent(lblNewLabel_5)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(manJrb)
							.addGap(32)
							.addComponent(femaleJrb))
						.addGroup(gl_userPanel.createSequentialGroup()
							.addGroup(gl_userPanel.createParallelGroup(Alignment.TRAILING)
								.addComponent(deleteButton)
								.addComponent(lblNewLabel_8))
							.addGap(18)
							.addComponent(emailTxt, GroupLayout.PREFERRED_SIZE, 192, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				.addGroup(gl_userPanel.createSequentialGroup()
					.addGap(226)
					.addComponent(alterButton)
					.addContainerGap(415, Short.MAX_VALUE))
		);
		gl_userPanel.setVerticalGroup(
			gl_userPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_userPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_userPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel_3)
						.addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(55)
					.addGroup(gl_userPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_4)
						.addComponent(passWordTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel_5)
						.addComponent(manJrb)
						.addComponent(femaleJrb))
					.addGap(59)
					.addGroup(gl_userPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_6)
						.addComponent(userTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(56)
					.addGroup(gl_userPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_7)
						.addComponent(telTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel_8)
						.addComponent(emailTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
					.addGroup(gl_userPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(alterButton)
						.addComponent(deleteButton)))
		);
		userPanel.setLayout(gl_userPanel);
		
		JLabel s_userName = new JLabel("用户名：");
		s_userName.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_userNameTxt = new JTextField();
		s_userNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_userNameTxt.setColumns(10);
		
		s_userType = new JLabel("用户类型：");
		s_userType.setFont(new Font("宋体", Font.BOLD, 25));
		
		
		
		String []types= {"学生","老师","系统管理员","图书管理员"};
		s_userTypeJcb = new JComboBox(types);
		s_userTypeJcb.setFont(new Font("宋体", Font.BOLD, 25));
		
		//s_userTypeJcb.addItem(h);
		
		JButton searchButton = new JButton("查询");
		searchButton.setIcon(new ImageIcon(UserImfManageInterFrm.class.getResource("/images/bookAdmi/查询.png")));
		searchButton.setFont(new Font("宋体", Font.BOLD, 28));
		searchButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				 userSearchActionPerformed(e);
			}
		});
		
		JButton s_cancelButton = new JButton("取消");
		s_cancelButton.setIcon(new ImageIcon(UserImfManageInterFrm.class.getResource("/images/bookAdmi/重置.png")));
		s_cancelButton.setFont(new Font("宋体", Font.BOLD, 25));
		s_cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				userSearchResetValueActionPerformed(e);
			}
		});
		
		JLabel s_tel = new JLabel("手机号码：");
		s_tel.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_telTxt = new JTextField();
		s_telTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_telTxt.setColumns(10);
		
		JLabel s_passWord = new JLabel("密   码：");
		s_passWord.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_passWordTxt = new JTextField();
		s_passWordTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_passWordTxt.setColumns(10);
		GroupLayout gl_userSearchPanel = new GroupLayout(userSearchPanel);
		gl_userSearchPanel.setHorizontalGroup(
			gl_userSearchPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_userSearchPanel.createSequentialGroup()
					.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_userSearchPanel.createSequentialGroup()
							.addContainerGap()
							.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(s_userName)
								.addComponent(s_tel))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.LEADING, false)
								.addComponent(s_telTxt)
								.addComponent(s_userNameTxt, GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)))
						.addGroup(gl_userSearchPanel.createSequentialGroup()
							.addGap(114)
							.addComponent(searchButton)))
					.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_userSearchPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
							.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(s_passWord)
								.addComponent(s_userType))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.LEADING, false)
								.addComponent(s_passWordTxt)
								.addComponent(s_userTypeJcb, 0, 196, Short.MAX_VALUE)))
						.addGroup(gl_userSearchPanel.createSequentialGroup()
							.addGap(58)
							.addComponent(s_cancelButton)))
					.addContainerGap(42, Short.MAX_VALUE))
		);
		gl_userSearchPanel.setVerticalGroup(
			gl_userSearchPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_userSearchPanel.createSequentialGroup()
					.addGap(34)
					.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(s_userName)
						.addComponent(s_userNameTxt, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
						.addComponent(s_userTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(s_userType))
					.addGap(34)
					.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(s_tel)
						.addComponent(s_telTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(s_passWordTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(s_passWord))
					.addPreferredGap(ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
					.addGroup(gl_userSearchPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(searchButton)
						.addComponent(s_cancelButton))
					.addContainerGap())
		);
		userSearchPanel.setLayout(gl_userSearchPanel);
		
		userTable = new JTable();
		userTable.setBackground(new Color(255, 218, 185));//设置表格背景颜色
		userTable.getTableHeader().setFont(new Font("微软雅黑",Font.BOLD,20));//设置表格开头字体
		userTable.getTableHeader().setBackground(new Color(255, 218, 185));//设置表格开头背景颜色
		userTable.setFont(new Font("楷体", Font.BOLD, 22));//设置表格内容字体
		userTable.setForeground(new Color(0,0,0));//设置表格内容字体颜色		
		userTable.setRowHeight(userTable.getRowHeight()+20);//设置表格内容的行高
		
		userTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				userTableMousePressed(e);
			}
		});
		userTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "\u7528\u6237\u540D", "\u5BC6\u7801", "\u6027\u522B", "\u7528\u6237\u7C7B\u578B", "\u624B\u673A\u53F7\u7801", "\u90AE\u4EF6"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		allUserImfScrollPane.setViewportView(userTable);
		getContentPane().setLayout(groupLayout);
		
		//设置JFrame居中显示
		this.setLocation(80, 0);
		
		this.fillTable(new User());

	}
	
	/**
	 * 用户信息删除事件处理
	 * @param e
	 */
	protected void userDeleteActionPerformed(ActionEvent evt) {
		String id=idTxt.getText();
		if(StringUtil.isEmpty(id)) {
			JOptionPane.showMessageDialog(null, "请选择要删除的记录！");
			return;
		}
		int n=JOptionPane.showConfirmDialog(null, "确定要删除这条记录吗?");
		if(n==0) {
			Connection con=null;
			try {
				con=dbUtil.getCon();
				int deleteNum=userDao.delete(con, id);
				if(deleteNum==1) {
					JOptionPane.showMessageDialog(null, "删除成功");
					this.reSetValue();
					this.fillTable(new User());
				}
				else {
					JOptionPane.showMessageDialog(null, "删除失败");
				}
			}catch(Exception e) {
				e.printStackTrace();
			}finally {
				try {
					dbUtil.closeCon(con);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
	}

	/**
	 * 用户信息修改事件
	 * @param e
	 */
	protected void userUpdateActionPerformed(ActionEvent evt) {
		String id=this.idTxt.getText();
		if(StringUtil.isEmpty(id)) {
			JOptionPane.showMessageDialog(null, "请选择要修改的记录！");
			return;
		}
			
			String userName=this.userNameTxt.getText();
			String passWord=this.passWordTxt.getText();
			String tel=this.telTxt.getText();
			String email=this.emailTxt.getText();
			String userType=(String)this.userTypeJcb.getSelectedItem();
			

			if(StringUtil.isEmpty(userName)) {
				JOptionPane.showMessageDialog(null, "用户名不能为空!");
				return;
			}
			
			if(StringUtil.isEmpty(passWord)) {
				JOptionPane.showMessageDialog(null, "密码不能为空!");
				return;
			}
			
			if(StringUtil.isEmpty(tel)) {
				JOptionPane.showMessageDialog(null, "手机号码不能为空!");
				return;
			}
			
			if(StringUtil.isEmpty(email)) {
				JOptionPane.showMessageDialog(null, "邮箱不能为空!");
				return;
			}
			
			
			String sex="";
			if(manJrb.isSelected()) {
				sex="男";
			}
			else if(femaleJrb.isSelected()) {
				sex="女";
			}
			
			User user=new User(Integer.parseInt(id),userName,passWord,sex,userType,tel,email);
			Connection con=null;
			try {
				con=dbUtil.getCon();
				int addNum=userDao.update(con, user);
				if(addNum==1) {
					JOptionPane.showMessageDialog(null,"用户信息修改成功" );
					reSetValue();
					this.fillTable(new User());
				}
				else {
					JOptionPane.showMessageDialog(null, "用户信息修改失败！");
				}
			}catch(Exception e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(null, "用户信息修改失败！");
			}finally {
				try {
					dbUtil.closeCon(con);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
	

	/**
	 * 取消事件处理
	 * @param e
	 */
	protected void userSearchResetValueActionPerformed(ActionEvent e) {
		this.s_passWordTxt.setText("");
		this.s_telTxt.setText("");
		this.s_userNameTxt.setText("");
		this.s_userTypeJcb.setSelectedIndex(0);	
		
	}

	/**
	 * 初始化表格数据
	 * @param book
	 */
	private void fillTable(User user) {
		DefaultTableModel dtm=(DefaultTableModel) userTable.getModel();
		dtm.setRowCount(0);//设置成0行
		Connection con=null;
		try {
			con=dbUtil.getCon();
			ResultSet rs=userDao.list(con, user);
			while(rs.next()) {
				Vector v=new Vector();
				v.add(rs.getString("id"));
				v.add(rs.getString("userName"));
				v.add(rs.getString("passWord"));
				v.add(rs.getString("sex"));
				v.add(rs.getString("userType"));
				v.add(rs.getString("tel"));
				v.add(rs.getString("email"));
				dtm.addRow(v);
			}
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
		
		
	/**
	 * 表格行点击事件处理
	 * @param me
	 */
	private void userTableMousePressed(MouseEvent met) {
		int row=this.userTable.getSelectedRow();
		this.idTxt.setText((String)userTable.getValueAt(row, 0));
		this.userNameTxt.setText((String)userTable.getValueAt(row, 1));
		this.passWordTxt.setText((String)userTable.getValueAt(row, 2));
		String sex=(String)userTable.getValueAt(row, 3);
		if("男".equals(sex)) {
			this.manJrb.setSelected(true);
		}else if("女".equals(sex)) {
			this.femaleJrb.setSelected(true);
		}
		
		String userType=(String)userTable.getValueAt(row, 4);	
		if("学生".equals(userType)) {
			this.userTypeJcb.setSelectedItem("学生");
		}
		else if("老师".equals(userType)) {
			this.userTypeJcb.setSelectedItem("老师");
		}
		else if("系统管理员".equals(userType)) {
			this.userTypeJcb.setSelectedItem("系统管理员");
		}
		else if("图书管理员".equals(userType)) {
			this.userTypeJcb.setSelectedItem("图书管理员");
		}
		
		
		this.telTxt.setText((String)userTable.getValueAt(row, 5));
		this.emailTxt.setText((String)userTable.getValueAt(row, 6));
	}
	
	
	/**
	 * 重置表单
	 */
	private void reSetValue() {
		this.idTxt.setText("");
		this.userNameTxt.setText("");
		this.passWordTxt.setText("");		
		this.manJrb.setSelected(true);		
		if(this.userTypeJcb.getItemCount()>0) {
			this.userTypeJcb.setSelectedIndex(0);		
		}		
		this.telTxt.setText("");
		this.emailTxt.setText("");
	}
	
	
	/**
	 * 用户信息查询事件处理
	 * @param e
	 */
	private void userSearchActionPerformed(ActionEvent evt) {
		String userName=this.s_userNameTxt.getText();
		String userType=(String) this.s_userTypeJcb.getSelectedItem();
		String tel=this.s_telTxt.getText();
		String passWord=this.s_passWordTxt.getText();
		User user=new User(userName,passWord,userType,tel);
		
		
		this.fillTable(user);
		
		
	}
}
